[PATCH] [InstCombine] Fix big-endian miscompile of (bitcast (zext/trunc (bitcast)))
authorBjorn Pettersson <bjorn.a.pettersson@ericsson.com>
Thu, 28 Nov 2019 22:18:28 +0000 (23:18 +0100)
committerGianfranco Costamagna <locutusofborg@debian.org>
Mon, 27 Sep 2021 15:53:42 +0000 (16:53 +0100)
commit584017d8b0a9da12a8f988584b429e568f168c50
treed294aa88ad48a3412d94aaa92de401cba0be0311
parentde97524f9d09727cdaab88c25aea893658213869
[PATCH] [InstCombine] Fix big-endian miscompile of (bitcast (zext/trunc (bitcast)))

Summary:
optimizeVectorResize is rewriting patterns like:
  %1 = bitcast vector %src to integer
  %2 = trunc/zext %1
  %dst = bitcast %2 to vector

Since bitcasting between integer an vector types gives
different integer values depending on endianness, we need
to take endianness into account. As it happens the old
implementation only produced the correct result for little
endian targets.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=44178
Reviewers: spatel, lattner, lebedev.ri

Reviewed By: spatel, lebedev.ri

Subscribers: lebedev.ri, hiraditya, uabelho, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70844

(cherry picked from commit a9d6b0e5444741d08ff1df7cf71d1559e7fefc1f)

Gbp-Pq: Name f8e146f3430de3a6cd904f3f3f7aa1bfaefee14c.patch
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/cast.ll